<template>
	<div class="shopDd">
		<div class="shopDd-address">
			<router-link to="/myaddress">
				<img src="../img-shopping/icon_adress@3x.png"/>
				<img src="../img-shopping/icon_next@3x.png"/>
				<div class="shopDd-userxinxi" v-if="user_address.consignee">
					<p><span>{{user_address.consignee}}</span><span id="telp">{{user_address.phone_mob==null?user_address.phone_tel:user_address.phone_mob}}</span></p>
					<p>{{user_address.region_name}} {{user_address.address}}</p>
				</div>
				<div class="shopDd-address-none" v-else>目前还没有收货地址，去新建一个</div>
			</router-link>
		</div>
		<div class="shopcard-listBox">
			<h3 class="shopcard-title"><i><img src="../img-shopping/icon_dianpu@3x.png"/></i><span>{{goods_xinxi.store_name}}</span></h3>
			<ul class="shopcard-list-item-box">
				<li class="shopcard-list-item" v-for="item in goods_xinxi.items">
					<div>
						<img :src="'http://www.ntyouxuan.com/'+item.goods_image"/>
						<div class="shopcard-list-item-xinxi">
							<h3>{{item.goods_name}}</h3>
							<p><span>{{item.specification}}</span></p>
							<div class="shopcard-item-num">
								<span>￥</span>
								<span>{{item.price_detail[0]}}.</span>
								<span>{{item.price_detail[1]}}</span>
								<p class="shopDd-itemnum">x{{item.quantity}}</p>
							</div>
						</div>
					</div>
					
				</li>	
			</ul>
			<div class="shopDd-liuyan"><span>买家留言：</span><input type="text" v-model="postscript" name="" id="" value="" placeholder="点击给商家留言"/></div>
			<div class="shopDd-list-heji"><span>共{{goods_xinxi.quantity}}件商品</span><span>合计</span><span>￥</span><span>{{goods_price[0]}}.</span><span>{{goods_price[1]}}</span></div>
		</div>
		<div class="shopDd-djbz" v-if="advance">
			<div class="shopDd-jd1">
				<h4>阶段1：定金￥{{advance.ad_money}}，抵扣￥{{advance.de_money}} <!--<span><img src="../img-address/icon_select @3x.png"/></span>--></h4>
				<p><span v-show="!adagree" @click="adagree=!adagree"><img src="../img-address/icon_dis@3x.png"/></span><span v-show="adagree" @click="adagree=!adagree"><img src="../img-address/icon_select @3x.png"/></span>我已同意<a>《定金不退等预售协议》</a></p>
			</div>
			<div class="shopDd-jd2">
				<h4>阶段2：尾款￥{{adweik}}</h4>
				<p>尾款支付时间：{{fa_btime}}-{{fa_etime}}</p>
				<p>支付尾款后发货</p>
			</div>
			<div class="shopDd-djtel"><span>通知支付尾款的手机号</span><span>{{user_address.phone_mob}}</span></div>
		</div>
		<ul class="shopDd-youhui">
			<li @click="youhuiquanbtn()"><span>优惠券</span><p><span>{{coupon_get}}</span><img src="../img-shopping/icon_next@3x.png"/></p></li>
			<li v-if="!advance" @click="hongbaobtn()"><span>红包</span><p><span v-text="packe_get"></span><img src="../img-shopping/icon_next@3x.png"/></p></li>
		</ul>
		<ul class="shopDd-zhangdan">
			<li>商品<span>￥{{goods_price[0]}}.{{goods_price[1]}}</span></li>
			<li>运费<span>+￥{{amount}}</span></li>
			<li>店铺优惠<span>-￥{{userDdxinxi.amount_pro==0?'0.00':userDdxinxi.amount_pro}}</span></li>
			<li v-if="!advance">平台红包<span>-￥{{packe_getNnm}}</span></li>
		</ul>
		<div class="shopDd-footer-heji">
			<span>合计：</span>
			<span>￥</span>
			<span>{{amount_detail[0]}}.</span>
			<span>{{amount_detail[1]}}</span>
			<span @click="shopDdtj()">提交订单</span>
		</div>
	</div>
</template>

<script>
	import shopDdCss from "../css/shopDd.css"
	var furl = 'http://www.ntyouxuan.com/';
	export default{
		name:"shopDd",
		data () {
			return{
				num:"",
				user:0,
				did:0,
				god:0,
				gidg:0,
				userDdxinxi:'',
				user_address:'',
				goods_xinxi:'',
				amount_detail:[],
				goods_price:[],
				coupon_get:"无优惠券可用",
				coupon_sn:0,
				packe_get:'无可用红包',
				packe_sn:0,
				packe_getNnm:"0.00",
				amount:'0.00',
				advance:"",
				adagree:true,
				fa_btime:"",
				fa_etime:"",
				adweik:"",
				postscript:''
			}
		},
		created:function(){
			this.did=this.$route.query.did;
			this.god=this.$route.query.god;
			this.gidg=this.$route.query.gidg;
			this.user=localStorage.getItem("nt_user");
			var pick_sn='',coupon_sn='',not_pack='',not_pre='';
			if(sessionStorage.getItem('hb_sn')){
				pick_sn=sessionStorage.getItem('hb_sn');
			};
			if(sessionStorage.getItem('yhq_sn')){
				coupon_sn=sessionStorage.getItem('yhq_sn');
			};
			if(sessionStorage.getItem('hb_zbsy')){
				not_pack=sessionStorage.getItem('hb_zbsy');
			};
			if(sessionStorage.getItem('yhq_zbsy')){
				not_pre=sessionStorage.getItem('yhq_zbsy');
			};
			
			var self=this;
			$.ajax({
				type:"get",
				url:furl+"index.php?app=ajax_order&act=index_ajax",
				data:{"token":self.user,"store_id":self.did,"goods_id":self.god,"spec_id":self.gidg,'packe_sn':pick_sn,'coupon_sn':coupon_sn,'not_pack':not_pack,'not_pre':not_pre},
				dataType:"json",
				success:function(res){
					if(!res.done){
						history.go(-1);
					}else{ 
						self.userDdxinxi=res.retval;
						self.userDdxinxi.amount_pro=self.userDdxinxi.amount_pro.toFixed(2);
						self.user_address=res.retval.my_address;
						if(res.retval.coupon_get){
							self.coupon_get="-￥"+res.retval.coupon_get.coupon_value;
							self.coupon_sn=res.retval.coupon_get.coupon_sn;
						}
						if(res.retval.packe_get){
							self.packe_get="-￥"+res.retval.packe_get.coupon_value;
							self.packe_getNnm=res.retval.packe_get.coupon_value;
							self.packe_sn=res.retval.packe_get.coupon_sn;
						}
						if(res.retval.region_free){
							for(var i=0;i<res.retval.region_free.amount.length;i++){
								self.amount=((Number(self.amount)*100+Number(res.retval.region_free.amount[i])*100)/100).toFixed(2);
								
							}						
						}
						if(res.retval.advance){
							self.advance=res.retval.advance;
							self.fa_btime=new Date(Number(res.retval.advance.fa_btime)*1000).Format("MM月dd日 hh:mm:ss");
							self.fa_etime=new Date(Number(res.retval.advance.fa_etime)*1000).Format("MM月dd日 hh:mm:ss");
							self.amount_detail=res.retval.advance.advance_amount_detail;
							self.adweik=(Number(res.retval.goods_info.amount)-Number(res.retval.advance.advance_de_amount)).toFixed(2);
						}else{
							self.amount_detail=res.retval.goods_info.amount_detail;
						}
						self.goods_xinxi=res.retval.goods_info;
						self.goods_price=res.retval.goods_info.goods_price;
						
					}
					
				}
			});
		},
		methods:{
			shopDdtj:function(){
				// 提示手机号
				var html = $('#telp').text();
				if(Number(html)){
				    
				}else{
					layer.open({
						content: '手机号未填写',
						skin: 'msg',
						time: 3 //3秒后自动关闭
					});
				};
				var self=this;
				$.ajax({
					type:"post",
					url:furl+"index.php?app=ajax_order&act=index_ajax_post",
					data:{"token":self.user,"store_id":self.did,"goods_id":self.god,"spec_id":self.gidg,"address_options":self.user_address.addr_id,"coupon_sn":self.coupon_sn,"packe_sn":self.packe_sn,'postscript':self.postscript},
					dataType:"json",
					success:function(res){
						var ddid=res.retval.order_id;
						sessionStorage.removeItem('hb_sn');
						sessionStorage.removeItem('yhq_sn');
						sessionStorage.removeItem('hb_zbsy');
						sessionStorage.removeItem('yhq_zbsy');
						self.$router.push({path:'/payrequet',query:{'ordertoken':ddid,'token':self.user}});
						self.jinzhizhi = res.done
						console.log(self.jinzhizhi)
					}
				})
				self.jinzhizhi = res.done
				if(self.jinzhizhi = false){
					alert("hhhhh")
				}
			},
			
			youhuiquanbtn:function(){
				this.$router.push({path:'/playdisyhq',query:{'storetoken':this.did,'goodstoken':this.god,'spectoken':this.gidg,'couponsn':this.packe_sn}});
			},
			hongbaobtn:function(){
				this.$router.push({path:'/playdishb',query:{'storetoken':this.did,'goodstoken':this.god,'spectoken':this.gidg,'couponsn':this.coupon_sn}});
			}
		}
	}
</script>

<style>
</style>